package com.trainoo.handler;

import com.trainoo.exception.GirlsException;
import com.trainoo.domain.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2017/6/5.
 * 统一异常处理方法
 */

@ControllerAdvice
public class ExceptionHandler {

    @org.springframework.web.bind.annotation.ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handler(Exception e){

        if(e instanceof GirlsException){
            Result result = new Result();
            GirlsException ge = (GirlsException)e;
            result.setCode(ge.getCode());
            result.setMsg(ge.getMessage());
            return result;
        }else{
            Result result = new Result();
            result.setCode(-1);
            result.setMsg("未知错误");
            return result;
        }
    }
}
